package com.aforce3.trailertracer.scenes;

import java.util.ArrayList;


import javax.media.j3d.Transform3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;

import com.aforce3.trailertracer.Ray;
import com.aforce3.trailertracer.optimizations.BoundingBox;

public abstract class Scene
{
	private Scene parent = null;
	protected Transform3D transformation = new Transform3D();

	public void SetTranform(Transform3D t)
	{
		transformation = t;
	}

	public Transform3D GetTransform()
	{
		return new Transform3D(transformation);
	}

	public abstract void applyTransform();
	protected abstract void applyTransform(Transform3D t);

	public abstract Color3f getColor(Ray ray, Scene child);

	public abstract Color3f getColor(Ray ray);

	public abstract float getDistance(Ray ray);

	public Point3d calculateIntersect(Ray ray)
	{
		float distance = getDistance(ray);
		if (distance > 0){
			Point3d intersect = new Point3d(ray.getDirection());
			intersect.scale(distance);
			intersect.add(ray.getSource());
			return intersect;
		}
		return null;
	}

	public Scene getParent()
	{
		return parent;
	}

	public void setParent(Scene scene)
	{
		this.parent = scene;
	}

	public Scene getRoot()
	{
		Scene c = this;
		Scene p = parent;
		while(p != null)
		{
			c = p;
			p = p.getParent();
		}
		return c;
	}

	public abstract ArrayList<PointLight> getLights();

	public abstract Scene getClosest(Ray ray, Scene self);

	public abstract Scene getClosestObject(Ray ray, Scene self);

	public boolean isLight()
	{
		return false;
	}
	
	public abstract BoundingBox getBoundingBox();
}
